package com.ctgu.controller;


import com.ctgu.common.ResponseResult;
import com.ctgu.model.entity.Company;
import com.ctgu.model.entity.Department;
import com.ctgu.service.IDepartmentService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yiMa
 * @since 2023-07-05
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @GetMapping("/list")
    @PreAuthorize("@AYM.hasAuthority('department:info:query')")
    public ResponseResult list(){
        return departmentService.getList();
    }

    @PostMapping("/add")
    @PreAuthorize("@AYM.hasAuthority('department:one:add')")
    public ResponseResult add(@RequestBody Department department){
        return departmentService.add(department);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("@AYM.hasAuthority('department:one:delete')")
    public ResponseResult delete(int id){
        return departmentService.delete(id);
    }

    @PutMapping("/updateInfo")
    @PreAuthorize("@AYM.hasAuthority('department:one:update')")
    public ResponseResult updateInfo(@RequestBody Department department){
        return departmentService.updateInfo(department);
    }

}

